//
//  BEMyOrdersListViewModel.swift
//  BEGlobalOiler
//
//  Created by KKING on 16/9/10.
//  Copyright © 2016年 Bullseye Energy pte ltd. All rights reserved.
//

import UIKit

class BEMyOrdersListViewModel: NSObject {
    //懒加载视图模型数组
    lazy var ordersViewModelData: [BEMyOrdersViewModel] = [BEMyOrdersViewModel]()
}


extension BEMyOrdersListViewModel{
    
    func loadOrderListData(orderStatus:Int,finished: @escaping (_ success: Bool, _ tip: String) -> ()) {
        BENetworkTools.shareNetworkTool.loadOrderListData(orderStatus: orderStatus) { (success, result, error) in
            
            guard let resultjson = result else {
                finished(false, "Network fault!")
                return
            }
            if resultjson["success"] == true {
                //此处增加字典转模型逻辑
                let data = resultjson["result"].arrayObject as! [[String : AnyObject]]
                for item in data{
                    let order = BEOrderModel(dict: item)
                    let viewMdl = BEMyOrdersViewModel(orderModel: order)
                    // mark 数据重复,需增加逻辑判断.
                    self.ordersViewModelData.append(viewMdl)
                }
                finished(true, "Load data success!")
            } else {
                finished(false, resultjson["message"].stringValue)
            }
            
        }
    }
}
